package com.duguo.dynamicmvc.view;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.duguo.dynamicmvc.model.Model;

public class ExceptionView implements View {
	
	public static String EXCEPTION_KEY="exception";
	
	private View targetView;
	private int status;
	private Exception exception;
	
    public ExceptionView(View targetView, int status, Exception exception) {
		this.targetView = targetView;
		this.status = status;
		this.exception = exception;
	}

	public void render(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
    	response.setStatus(status);
    	request.setAttribute(EXCEPTION_KEY, exception);
    	targetView.render(request, response, model);
    }

	public String getViewName() {
		return targetView.getViewName();
	}
    
}
